import 'dart:convert' show json;

import 'package:flutter_common_app/data/protection.dart';

class RecommendPlaylistData {
  RecommendPlaylistData({
    this.id,
    this.type,
    this.name,
    this.copywriter,
    this.picUrl,
    this.canDislike,
    this.trackNumberUpdateTime,
    this.playCount,
    this.trackCount,
    this.highQuality,
    this.alg,
  });

  factory RecommendPlaylistData.fromJson(Map<String, dynamic> jsonRes) =>
      jsonRes == null
          ? null
          : RecommendPlaylistData(
              id: asT<int>(jsonRes['id']),
              type: asT<int>(jsonRes['type']),
              name: asT<String>(jsonRes['name']),
              copywriter: asT<String>(jsonRes['copywriter']),
              picUrl: asT<String>(jsonRes['picUrl']),
              canDislike: asT<bool>(jsonRes['canDislike']),
              trackNumberUpdateTime: asT<int>(jsonRes['trackNumberUpdateTime']),
              playCount: asT<int>(jsonRes['playCount']),
              trackCount: asT<int>(jsonRes['trackCount']),
              highQuality: asT<bool>(jsonRes['highQuality']),
              alg: asT<String>(jsonRes['alg']),
            );

  int id;
  int type;
  String name;
  String copywriter;
  String picUrl;
  bool canDislike;
  int trackNumberUpdateTime;
  int playCount;
  int trackCount;
  bool highQuality;
  String alg;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'id': id,
        'type': type,
        'name': name,
        'copywriter': copywriter,
        'picUrl': picUrl,
        'canDislike': canDislike,
        'trackNumberUpdateTime': trackNumberUpdateTime,
        'playCount': playCount,
        'trackCount': trackCount,
        'highQuality': highQuality,
        'alg': alg,
      };

  @override
  String toString() {
    return json.encode(this);
  }

  static List<RecommendPlaylistData> fromJsonList(List json){
      return json.map((item) => RecommendPlaylistData.fromJson(item)).toList();
  }
}
